<?php

namespace App\ApiBackend\Admin;

use App\Domains\UserDao;
use App\Http\Controllers\ApiBaseController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;

/**
 *  用户状态
 */
class Status extends ApiBaseController
{


  /**
   * 参数检查
   */
  protected function check(): void
  {
    try {
      request()->validate([
        'adminId' => 'required',
        'status' => 'required',
      ]);
    } catch (\Exception $exception) {
      $this->result["code"] = 1;
      $this->result["message"] = "预检: " . $exception->getMessage();
    }
  }

  /**
   * 业务主体
   */
  protected function service(): void
  {
    //更新数据
    try {
      DB::table('admin')->where('adminId', request('adminId'))->update([
        'status' => request('status')
      ]);
      $this->result["message"] = "更改状态成功";
    } catch (\Exception $exception) {
      $this->result["code"] = 2;
      $this->result["message"] = "失败: " . $exception->getMessage();
    }
  }
}
